% This script puts all the analysis functions into a complete workflow

% IMPORTANT: before you run anything, make sure the following:
% 1. In getdsap, set file names & file paths you want, or else things will
% run for some datasets unexpectedly and it will get really messy
% 2. Have metadata excel sheet correctly filled out

%% Primary Analysis
% Output: inscopix raw recording fully processed, 
% plus all the inscopix raw data csv files

% if you need to re-run primary analysis, you have to delete
% previously-generated results; to do this, go to Preprocessing and CNMFE
% Analysis folder and find Delete_results.m, and simply run that function.

runPrimaryBatchAnalysis;

%% Get Recording Start Times (posix time)
% Output: a new secondary metadata excel sheet
[ds, ap]=getdsap;
getSessionPairStartTimes(ds, ap);

%% Place Cell Analysis
% Output: a MAT file that summarizes place cell information 
% (as defined by Mutual Information) for all recordings
Get_Place_Cell_Info_For_All_Cellsets;

%% Spatial Engram Analysis (Event-Rate, Rate-Map, Population-Vector)
% Output: a MAT file that summarizes ER, RM, and PV analysis results, in
% addition to many other parameters (e.g. cell recurring probability, 
% mobiltiy, proportion of coactive cells, total number of cells active, etc.)
runEngramAnalysis;

%% Mobility and Event Rate Analysis 
% detailed analysis of the relationship between mobility and ER
% non-parallelized analysis because it takes pretty short to complete
runMobility_and_ER_Analysis;

%% Cross-Day Analysis
% Output: two MAT files summarizing cross-day analysis based on PM/day2 sessions
% that use different contexts. It is used as a control and exploration of how
% memory drifts over time in calcium imaging recordings.
runXDayAnalysis;

% clear all variables (data are all saved on local drive, no need to have them in workspace)
clear